/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package ecarx.xsf.notificationcenter.sdk;

import android.app.PendingIntent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.StringDef;


/**
 * FileName: IStatusBarAction.java <br>
 * Description : 触达层的响应事件<br>
 * Create Time: 2021/9/2 11:40 <br>
 * Update Time: 2021/9/2 11:40 <br>
 *
 * @since 1.0.0
 */
public class IStatusBarAction implements Parcelable {


    /**
     * ACTION ID key
     */
    private static final String KEY_ID = "id";

    /**
     * button 标题，或可见即可说标题
     */
    private static final String KEY_TEXT = "text";

    /**
     * 按钮资源图 KEY
     */
    private static final String KEY_BG_URL = "bgUrl";

    /**
     * 功能函数id
     */
    private static final String KEY_FUNCTION_ID = "functionId";

    /**
     * pending intent KEY
     */
    private static final String KEY_PENDING_INTENT = "pending_intent";


    @StringDef({KEY_ID, KEY_TEXT, KEY_BG_URL, KEY_FUNCTION_ID, KEY_PENDING_INTENT})
    @interface ActionKey {
    }

    /**
     * 动作事件数据实例
     */
    private final Bundle extra;

    public IStatusBarAction(int id, String text, String bgUrl, String functionId, PendingIntent intent) {
        extra = new Bundle();
        extra.putInt(KEY_ID, id);
        extra.putString(KEY_TEXT, text);
        extra.putString(KEY_BG_URL, bgUrl);
        extra.putString(KEY_FUNCTION_ID, functionId);
        extra.putParcelable(KEY_PENDING_INTENT, intent);
    }

    public IStatusBarAction(Bundle extra) {
        this.extra = extra;
    }

    public Bundle getExtra() {
        return extra;
    }

    public IStatusBarAction(Parcel in) {
        extra = in.readBundle(getClass().getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeBundle(extra);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<IStatusBarAction> CREATOR = new Creator<IStatusBarAction>() {
        @Override
        public IStatusBarAction createFromParcel(Parcel in) {
            return new IStatusBarAction(in);
        }

        @Override
        public IStatusBarAction[] newArray(int size) {
            return new IStatusBarAction[size];
        }
    };

    /**
     * * 响应事件 ID.
     * <p> 响应事件动作 ID ，默认值为0 <br>
     *
     * @return action 事件 ID
     * @since 1.0.0
     */
    public int getId() {
        if (extra != null) {
            return extra.getInt(KEY_ID, 0);
        }
        return 0;
    }

    /**
     * * 事件文本描述.
     * <p> 响应事件文本，默认为空字符串 <br>
     *
     * @return 按钮标题，可见即可说标题等
     * @since 1.0.0
     */
    public String getText() {
        if (extra != null) {
            return extra.getString(KEY_TEXT, "");
        }
        return "";
    }

    /**
     * * 按钮资源背景图标.
     * <p> 按钮背景资源图标，默认为空字符串 <br>
     *
     * @return 按钮背景资源图标
     * @since 1.0.0
     */
    public String getBgUrl() {
        if (extra != null) {
            return extra.getString(KEY_BG_URL, "");
        }
        return "";
    }

    /**
     * * 功能 ID.
     * <p> 功能 ID，默认为空字符串 <br>
     *
     * @return 功能ID，一般指场景卡片
     * @since 1.0.0
     */
    public String getFunctionId() {
        if (extra != null) {
            return extra.getString(KEY_FUNCTION_ID, "");
        }
        return "";
    }

    /**
     * * 动作事件.
     * <p> 按钮动作，可见即可说等事件 <br>
     *
     * @return 动作事件
     * @since 1.0.0
     */
    public PendingIntent getPendingIntent() {
        if (extra != null) {
            return extra.getParcelable(KEY_PENDING_INTENT);
        }
        return null;
    }
}
